/*************************************************************************
    > File Name    : DirScanner.cc
    > Author       : LiuLei
    > Mail         : 2261459486@qq.com 
    > Created Time : 2022年11月29日 星期二 14时51分06秒
 ************************************************************************/

#include "../../include/WebProcessor/DirScanner.h"
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
using std::cout;
using std::endl;

DirScanner::DirScanner()
{

}

DirScanner::~DirScanner()
{

}

void DirScanner::operator()(const string &dir)
{
    DIR *pdir = ::opendir(dir.c_str());
    if(nullptr == pdir)
    {
        ::perror("::opendir in DirScanner::operator()");
        return ;
    }

    struct dirent *pdirent;
    while(pdirent = ::readdir(pdir))
    {
        if(::strcmp(pdirent->d_name, ".") == 0 || ::strcmp(pdirent->d_name, "..") == 0)
        {
            continue;
        }
        string path;
        path += dir + "/" + pdirent->d_name;
        _files.push_back(path);
    }
    ::closedir(pdir);
}

vector<string> &DirScanner::getFilePath()
{
    return _files;
}

void DirScanner::printFiles() const
{
    for(auto &elem : _files)
    {
        cout << elem << endl;
    }
}
